<template>
  <uni-nav-bar title="消息推送" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <view class="package">
    <input class="uni-input" confirm-type="search" placeholder="搜索手机号/姓名" @confirm="confirm" v-model="search"
      @input="interrogate" />
  </view>
  <scroll-view scroll-y="true" enable-back-to-top @scrolltolower="loadMore" class="scroll-box"
    :style="{ height: pageHeight + 'px' }">
    <FriendList @jump="jump" :frinedList="frinedList" :userID="userID"></FriendList>
  </scroll-view>
  <view class="add">确认</view>
</template>

<script setup lang="ts">
  import { navBack } from '@/utils/navigator';
  import { ref } from 'vue';
  import FriendList from '@c/administrator/List/friendList.vue';
  import { errorToast, showLoading } from '@/utils/prompt';
  import { toPublish } from '@mqtt';
  import { getDriverList } from '@/gql/administrator';
  /**
   * 身份管理
   * @property {String} search 搜索内容
   * @property {Boolean} inquireAbout 是否确认已搜索
   * @property {String} pageHeight 滑动高度
   * @property {Array} frinedList 车友列表
   * @property {Number} lastPage 总页数
   * @property {Number} currentPage 当前页数
   */
  const search = ref('')
  const inquireAbout = ref(false)
  const pageHeight = ref();

  const frinedList = ref([])
  const lastPage = ref(1);
  const currentPage = ref(1);
  const userID = ref()
  uni.getSystemInfo({
    success: function (res) {
      pageHeight.value = res.windowHeight - 120;
    },
  });
  /**
   * 获取车友信息
   * @param {Number} page  获取当前页加注数据
   * @param {String} keywords  搜索信息
   */
  function init() {
    showLoading()
    const payload = {
      query: getDriverList,
      variables: {
        page: currentPage.value,
        keywords: search.value
      },
    };
    toPublish(
      'ql/control/getDriverList',
      payload,
      (obj : any) => {
        const { getDriverList } = obj.data;
        frinedList.value = [...frinedList.value, ...getDriverList.list];
        lastPage.value = getDriverList.lastpage;
      }
    );
  }
  /**
   * 加载更多
   */
  function loadMore() {
    if (currentPage.value < lastPage.value) {
      currentPage.value++;
      init();
    }
  }
  /**
   * 搜索内容
   */
  function interrogate(evt : any) {
    const { detail } = evt;
    if (!detail.value && inquireAbout) {
    }
  }
  /**
   * 搜索车友信息
   */
  function confirm() {
    if (search.value) {
      inquireAbout.value = search.value ? true : false;
      currentPage.value = 1;
      frinedList.value = [];
      init();
    } else {
      errorToast('请输入您要搜索的内容')
    }
  }
  function jump(id : number) {
    userID.value = id
  }
</script>

<style scoped lang="less">
  .add {
    width: 480rpx;
    height: 100rpx;
    background: linear-gradient(-10deg, #2C96F9, #1B91FF);
    border-radius: 5px;
    text-align: center;
    line-height: 100rpx;
    color: #fff;
    margin: 20rpx auto;
    font-size: 32rpx;
  }
</style>